package com.appspot.inkisapi.service;

import java.util.List;

import com.appspot.inkisapi.entity.BlogPost;

public class BlogPostService {
	public static void addOrUpdateBlogPost(BlogPost bp) throws Exception {
		OfyService.ofy().save().entity(bp);
	}

	public static BlogPost getBlogPost(Long id) {
		BlogPost bp = OfyService.ofy().load().type(BlogPost.class).id(id).get();
		return bp;
	}

	public static List<BlogPost> getAllBlogPosts() {
		return OfyService.ofy().load().type(BlogPost.class).order("-date").list();
	}
	
	public static List<BlogPost> getBlogPostsWith(String condition, String value) {
		return OfyService.ofy().load().type(BlogPost.class).filter(condition, value).order("-date").list();
	}

	public static void deleteBlogPost(Long id) throws Exception {
		OfyService.ofy().delete().type(BlogPost.class).id(id).now();
	}
}
